package com.zhangquancheng.shirodemo.exception;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author: zhangquancheng
 * @Description: 全剧异常处理
 * @Date: 2022/7/15 6:01 下午
 */
@ControllerAdvice//controller增强器，捕获controller异常
public class MyExcetionHandler {

    /**
     * @Description 未授权
     */
    @ExceptionHandler(UnauthorizedException.class)
    public String handlerUnauthorizedException(UnauthorizedException exception){
        System.err.println("handlerUnauthorizedException");
        exception.printStackTrace();
        return "/403";
    }

    /**
     * @Description 未认证
     */
//    @RequestBody
    @ExceptionHandler(UnauthenticatedException.class)
    public String unauthenticatedException(UnauthenticatedException exception){
        System.err.println("UnauthenticatedException");
        exception.printStackTrace();
        return "/toLogin";
    }
}
